package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.dto.DeviceDataDto;
import com.zzyl.nursing.domain.FamilyMemberElder;
import com.zzyl.nursing.dto.DevicePropertyDto;
import com.zzyl.nursing.dto.FamilyMemberAddDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IFamilyMemberElderService;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 老人家属Controller
 * 
 * @author ruoyi
 * @date 2025-04-26
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;

    @Autowired
    private IFamilyMemberElderService familyMemberElderService;


    @PostMapping("/login")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto){
        LoginVo vo = familyMemberService.login(dto);
        return success(vo);
    }
    /**
     * 按天查询指标数据
     */
    @GetMapping("/queryDeviceDataListByDay")
    public R<List<DeviceDataByDayVo>> queryDeviceDataListByDay(DeviceDataDto deviceDataDto){
        List<DeviceDataByDayVo> dayList  =familyMemberService.queryByDay( deviceDataDto);
        return R.ok(dayList);
    }
    /**
     * 按周查询指标数据
     */
    @GetMapping("/queryDeviceDataListByWeek")
    public R<List<DeviceDataByWeekVo>> queryDeviceDataListByWeek(DeviceDataDto deviceDataDto){
        List<DeviceDataByWeekVo> weekList  =familyMemberService.queryByWeek( deviceDataDto);
        return R.ok(weekList);
    }

    /**
     * 绑定老人
     * @param dto
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("绑定老人")
    public AjaxResult bind(@RequestBody FamilyMemberAddDto dto){
        return success(familyMemberService.bind(dto));
    }

    @GetMapping("/my")
    @ApiOperation("查询家人列表")
    public AjaxResult list(){
        List<FamilyMemberElder> familyMemberElder = familyMemberElderService.my();
        return success(familyMemberElder);
    }

    @GetMapping("/list-by-page")
    @ApiOperation("分页查询家人列表")
    public AjaxResult list(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                           @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        List<MemberVO> list = familyMemberService.listByPage(pageNum, pageSize);
        return success(list);
    }

    /**
     * 查询健康数据
     */
    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation("查询健康数据")
    public AjaxResult queryDevicePropertyStatus(@RequestBody DevicePropertyDto dto){
        DevicePropertyVo response = familyMemberService.queryDevicePropertyStatus(dto);
        return success(response);
    }


    /**
     * 解绑老人
     *
     * @param
     * @return
     */
    @DeleteMapping("/deleteById")
    @ApiOperation("解绑老人")
    public AjaxResult deleteById(@RequestParam Long elderId) {
        familyMemberService.removeElder(elderId);
        return success();
    }


}
